home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Examples / DemoDialogs / UDemoDialogs.inc1.p < prev    next >
Encoding:
Text File  |  1990-10-25  |  44.0 KB  |  1,611 lines  |  [TEXT/MPS ]

  1. {$P}
  2. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n+]}
  3. { UDemoDialogs.inc1.p }
  4. { Copyright © 1988 - 1990 Apple Computer, Inc.    All rights reserved. }
  5.  
  6. {--------------------------------------------------------------------------------------------------}
  7.  
  8. CONST
  9.     kNoOfLines            = 10000;
  10.     kMaxScrollBar        = 1000;
  11.     kTestIcon            = 1000;
  12.     kTestAlert            = 1000;
  13.     kTestPopup            =  235;
  14.     kBaudPopup            =  236;
  15.     kParityPopup        =  237;
  16.     kTestPicture        = 1000;
  17.     kTestStatic         = 1000;
  18.     kMaxPlaces            =   13;
  19.  
  20.     cFirstItem            = 1001;
  21.     cProcedureViews     = 1001;
  22.     cTemplateViews        = 1002;
  23.     cMonthlyDialog        = 1003;
  24.     cSaveDialog         = 1004;
  25.     cMarkDialog         = 1005;
  26.     cPageSetupDialog    = 1006;
  27.     cHomeBrewControls    = 1007;
  28.     cTabbingTest        = 1008;
  29.     cCalculator         = 1009;
  30.     cScrollingTest        = 1011;
  31.     cFormatDialog        = 1012;
  32.     cModelessMarkDialog = 1013;
  33.     cLastItem            = 1013;
  34.     cPopupExample        = 1100;
  35.  
  36.     mUpArrow            =  100;
  37.     mDownArrow            =  101;
  38.     mTemperatureChanged =  102;
  39.     
  40. TYPE
  41.     FondHandle            = ^FondPointer;
  42.     FondPointer         = ^FondRecord;
  43.     FondRecord            = RECORD
  44.         familyStuff:        FamRec;
  45.         noOfFonts:            INTEGER;
  46.         fontStuff:            ARRAY [0..1000] OF RECORD
  47.                             size:                INTEGER;
  48.                             style:                INTEGER;
  49.                             resID:                INTEGER;
  50.                             END;
  51.         END;
  52.  
  53.  
  54. VAR
  55.     gMonthlyValues:     ARRAY [1..12] OF LONGINT;
  56.     gMonthIDs:            ARRAY [1..12] OF IDType;
  57.  
  58.  
  59. {******************************************************************************************}
  60. {  T T e s t A p p l i c a t i o n                }
  61. {******************************************************************************************}
  62. {--------------------------------------------------------------------------------------------------}
  63.  
  64. {$S AInit}
  65. PROCEDURE TTestApplication.ITestApplication(itsMainFileType: OSType);
  66.  
  67.     VAR
  68.         i:                    INTEGER;
  69.         monthIDs:            PACKED ARRAY [1..48] OF CHAR;
  70.  
  71.     BEGIN
  72.     IApplication(itsMainFileType);
  73.     fLaunchWithNewDocument := FALSE;        { Suppress the creation of a new document at launch }
  74.  
  75.     FOR i := 1 TO 12 DO
  76.         gMonthlyValues[i] := i * 100;
  77.     monthIDs := 'jan feb mar apr may jun jul aug sep oct nov dec ';
  78.     BlockMove(@monthIDs, @gMonthIDs, SIZEOF(gMonthIDs));
  79.  
  80.     { Suppress dead-stripping of the following classes }
  81.     IF gDeadStripSuppression THEN
  82.         BEGIN
  83.         IF Member(TObject(NIL), TMonthlyDialog) THEN;
  84.         IF Member(TObject(NIL), TArrowsControl) THEN;
  85.         IF Member(TObject(NIL), TTemperatureCluster) THEN;
  86.         IF Member(TObject(NIL), TTemperatureConversionCluster) THEN;
  87.         IF Member(TObject(NIL), TSlider) THEN;
  88.         IF Member(TObject(NIL), THomeBrewDialog) THEN;
  89.         IF Member(TObject(NIL), TFontListView) THEN;
  90.         IF Member(TObject(NIL), TSizeListView) THEN;
  91.         IF Member(TObject(NIL), TRadioIcon) THEN;
  92.         IF Member(TObject(NIL), TPageSetupDialog) THEN;
  93.         IF Member(TObject(NIL), TSumStaticText) THEN;
  94.         IF Member(TObject(NIL), TCalcDialog) THEN;
  95.         IF Member(TObject(NIL), TNumbersView) THEN;
  96.         IF Member(TObject(NIL), TModelessMarkDialog) THEN;
  97.         IF Member(TObject(NIL), TScrollBar) THEN;
  98.         END;
  99.     END;
  100.  
  101. {--------------------------------------------------------------------------------------------------}
  102. {$S ASelCommand}
  103.  
  104. FUNCTION TTestApplication.DoMenuCommand(aCmdNumber: CmdNumber): TCommand;
  105.  
  106. {--------------------------------------------------------------------------------------------------}
  107.  
  108.     PROCEDURE MakeProcedureViews;
  109.  
  110.         VAR
  111.             i:                    INTEGER;
  112.             iStyle:                StyleItem;
  113.             oneStyle:            Set OF StyleItem;
  114.             aColor:             RGBColor;
  115.             itsLocation:        VPoint;
  116.             itsSize:            VPoint;
  117.             ts:                 TextStyle;
  118.             aWindow:            TWindow;
  119.             aDialogView:        TDialogView;
  120.             aCluster:            TCluster;
  121.             aRadio:             ARRAY [0..7] OF TRadio;
  122.             aButton:            TButton;
  123.             anIcon:             TIcon;
  124.             aCheckBox:            TCheckBox;
  125.             aPopup:             TPopup;
  126.             aPicture:            TPicture;
  127.             aStaticText:        TStaticText;
  128.             anEditText:         TEditText;
  129.  
  130.         BEGIN
  131.         NEW(aDialogView);
  132.         FailNIL(aDialogView);
  133.         SetVPt(itsSize, 480, 900);
  134.         aDialogView.IDialogView(NIL, NIL, gZeroVPt, itsSize, SizeFixed, SizeFixed,
  135.                                 kNoIdentifier, kNoIdentifier);
  136.         aDialogView.ParamTxt('^0', 'PARAM0');
  137.         aDialogView.ParamTxt('^1', 'PARAM1');
  138.  
  139.         aWindow := NewSimpleWindow(aCmdNumber, TRUE, TRUE, NIL, aDialogView);
  140.         aWindow.fFreeOnClosing := TRUE;
  141.         aWindow.SimpleStagger(kStdStaggerAmount, kStdStaggerAmount, gStdStaggerCount);
  142.  
  143.         NEW(aStaticText);
  144.         FailNIL(aStaticText);
  145.         SetVPt(itsLocation, 50, 100);
  146.         SetVPt(itsSize, 300, 150);
  147.         aStaticText.IStaticText(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable,
  148.                                 kTestStatic, 1);
  149.         SetRGBColor(aColor, 0, 0, $FFFF);
  150.         SetTextStyle(ts, applFont, [italic], 12, aColor);
  151.         aStaticText.InstallTextStyle(ts, kDontRedraw);
  152.         aStaticText.SetJustification(teJustCenter, kRedraw);
  153.  
  154.         NEW(aCluster);
  155.         FailNIL(aCluster);
  156.         SetVPt(itsLocation, 100, 340);
  157.         SetVPt(itsSize, 150, 190);
  158.         aCluster.ICluster(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable,
  159.                           kNoResource, 0);
  160.         aCluster.SetLabel('A Cluster!', kRedraw);
  161.  
  162.         SetVPt(itsSize, 130, 20);
  163.         oneStyle := [];                                    { no styles = plain }
  164.         iStyle := bold;
  165.         FOR i := 0 TO 7 DO
  166.             BEGIN
  167.             NEW(aRadio[i]);
  168.             FailNIL(aRadio[i]);
  169.             SetVPt(itsLocation, 10, (i + 1) * 20);
  170.             aRadio[i].IRadio(aCluster, itsLocation, itsSize, sizeVariable, sizeVariable, '', i = 2);
  171.             SetTextStyle(ts, systemFont, oneStyle, 12, gRGBBlack);
  172.             aRadio[i].InstallTextStyle(ts, kDontRedraw);
  173.             CASE i OF
  174.                 0:
  175.                     aRadio[i].SetText('Plain', kRedraw);
  176.                 1:
  177.                     aRadio[i].SetText('Bold', kRedraw);
  178.                 2:
  179.                     aRadio[i].SetText('Italic', kRedraw);
  180.                 3:
  181.                     aRadio[i].SetText('Underline', kRedraw);
  182.                 4:
  183.                     aRadio[i].SetText('Outline', kRedraw);
  184.                 5:
  185.                     aRadio[i].SetText('Shadow', kRedraw);
  186.                 6:
  187.                     aRadio[i].SetText('Condense', kRedraw);
  188.                 7:
  189.                     aRadio[i].SetText('Extend', kRedraw);
  190.                 END;
  191.             oneStyle := [iStyle];
  192.             iStyle := SUCC(iStyle);
  193.             END;
  194.  
  195.         NEW(aCheckBox);
  196.         FailNIL(aCheckBox);
  197.         SetVPt(itsLocation, 100, 540);
  198.         SetVPt(itsSize, 100, 20);
  199.         aCheckBox.ICheckBox(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable,
  200.                             'Check Box', FALSE);
  201.         SetTextStyle(ts, applFont, [], 12, gRGBBlack);
  202.         aCheckBox.InstallTextStyle(ts, kRedraw);
  203.  
  204.         NEW(aButton);
  205.         FailNIL(aButton);
  206.         SetVPt(itsLocation, 270, 540);
  207.         SetVPt(itsSize, 100, 28);
  208.         aButton.IButton(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable,
  209.                         'Push Button');
  210.         SetTextStyle(ts, applFont, [], 10, gRGBBlack);
  211.         aButton.InstallTextStyle(ts, kDontRedraw);
  212.         aButton.fAdornment := [adnRRect];
  213.         aButton.fPenSize := Point($00030003);
  214.         aButton.Inset(4, 4, kRedraw);
  215.  
  216.         NEW(anIcon);
  217.         FailNIL(anIcon);
  218.         SetVPt(itsLocation, 130, 570);
  219.         SetVPt(itsSize, 35, 35);
  220.         anIcon.IIcon(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable, kTestIcon,
  221.                      kPreferColor);
  222.         anIcon.fAdornment := kFrame + [adnShadow];
  223.         anIcon.ViewEnable(TRUE, kDontRedraw);
  224.         anIcon.Inset(1, 1, kDontRedraw);
  225.  
  226.         IF qNeedsHierarchicalMenus | gConfiguration.hasHierarchicalMenus THEN
  227.             BEGIN
  228.             NEW(aPopup);                                                { test popup }
  229.             FailNIL(aPopup);
  230.             SetVPt(itsLocation, 290, 589);
  231.             SetVPt(itsSize, 120, 22);
  232.             aPopup.IPopup(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable, kTestPopup,
  233.                           2, 50);
  234.  
  235.             NEW(aPopup);                                                { baud popup }
  236.             FailNIL(aPopup);
  237.             SetVPt(itsLocation, 290, 624);
  238.             SetVPt(itsSize, 120, 22);
  239.             aPopup.IPopup(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable, kBaudPopup,
  240.                           1, 50);
  241.  
  242.             NEW(aPopup);                                                { parity popup }
  243.             FailNIL(aPopup);
  244.             SetVPt(itsLocation, 290, 659);
  245.             SetVPt(itsSize, 120, 22);
  246.             aPopup.IPopup(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable, kParityPopup,
  247.                           1, 50);
  248.             END;
  249.  
  250.         NEW(aPicture);
  251.         FailNIL(aPicture);
  252.         SetVPt(itsLocation, 100, 660);
  253.         SetVPt(itsSize, $18C - $F0 + 16, $12C - $8F + 16);
  254.         aPicture.IPicture(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable,
  255.                           kTestPicture);
  256.         aPicture.fPenSize := Point($00020002);
  257.         aPicture.fAdornment := [adnRRect, adnShadow];
  258.         aPicture.ViewEnable(TRUE, kDontRedraw);
  259.         aPicture.Inset(8, 8, kDontRedraw);
  260.  
  261.         NEW(aStaticText);
  262.         FailNIL(aStaticText);
  263.         SetVPt(itsLocation, 20, 620);
  264.         SetVPt(itsSize, 100, 20);
  265.         aStaticText.IStaticText(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable,
  266.                                 kTestStatic, 2);
  267.         SetRGBColor(aColor, $FFFF, 0, 0);
  268.         aStaticText.InstallColor(aColor, kRedraw);
  269.  
  270.         NEW(anEditText);
  271.         FailNIL(anEditText);
  272.         SetVPt(itsLocation, 140, 620);
  273.         SetVPt(itsSize, 100, 22);
  274.         anEditText.IEditText(aDialogView, itsLocation, itsSize, 255);
  275.         SetTextStyle(ts, applFont, [], 12, gRGBBlack);
  276.         anEditText.InstallTextStyle(ts, kDontRedraw);
  277.         anEditText.SetJustification(teJustRight, kDontRedraw);
  278.         anEditText.SetText('EditText', kRedraw);
  279.  
  280. {        aDialogView.DoSelectEditText(anEditText, TRUE);    * select text and scroll it into view }
  281.         aWindow.Open;
  282.         END;
  283.  
  284. {--------------------------------------------------------------------------------------------------}
  285.  
  286.     PROCEDURE MakeTemplateViews;
  287.  
  288.         VAR
  289.             aWindow:            TWindow;
  290.             aDialogView:        TDialogView;
  291.             aPopup:             TPopup;
  292.  
  293.         BEGIN
  294.         aWindow := NewTemplateWindow(aCmdNumber, NIL);
  295.         FailNIL(aWindow);
  296.         aDialogView := TDialogView(aWindow.FindSubView('DLOG'));
  297.         IF qNeedsHierarchicalMenus | gConfiguration.hasHierarchicalMenus THEN
  298.             aPopup := TPopup(DoCreateViews(NIL, aDialogView, cPopupExample, gZeroVPt));
  299.         aDialogView.ParamTxt('^0', 'PARAM0');
  300.         aDialogView.ParamTxt('^1', 'PARAM1');
  301.         aWindow.Open;
  302.         END;
  303.  
  304. {--------------------------------------------------------------------------------------------------}
  305.  
  306.     PROCEDURE MakeScrollingTest;
  307.  
  308.         VAR
  309.             aWindow:            TWindow;
  310.             minSize:            Point;
  311.  
  312.         BEGIN
  313.         aWindow := NewTemplateWindow(aCmdNumber, NIL);
  314.         FailNIL(aWindow);
  315.         SetPt(minSize, 315, 260);
  316.         aWindow.SetResizeLimits(minSize, aWindow.fResizeLimits.botRight);
  317.         aWindow.Open;
  318.         END;
  319.  
  320. {--------------------------------------------------------------------------------------------------}
  321.  
  322.     PROCEDURE MakeMonthlyDialog;
  323.  
  324.         VAR
  325.             aWindow:            TWindow;
  326.             aMonthlyDialog:     TMonthlyDialog;
  327.  
  328.         BEGIN
  329.         aWindow := NewTemplateWindow(aCmdNumber, NIL);
  330.         FailNIL(aWindow);
  331.         aMonthlyDialog := TMonthlyDialog(aWindow.FindSubView('DLOG'));
  332.         IF aMonthlyDialog <> NIL THEN
  333.             aMonthlyDialog.StuffValues;
  334.         aWindow.Open;
  335.         END;
  336.  
  337. {--------------------------------------------------------------------------------------------------}
  338.  
  339.     PROCEDURE MakeSaveDialog;
  340.  
  341.         VAR
  342.             aWindow:            TWindow;
  343.             dismisser:            IDType;
  344.  
  345.         BEGIN
  346.         aWindow := NewTemplateWindow(aCmdNumber, NIL);
  347.         FailNIL(aWindow);
  348.         dismisser := TDialogView(aWindow.FindSubView('DLOG')).PoseModally;
  349.  
  350.         {$IFC qDebug}
  351.         IF dismisser = 'yes ' THEN
  352.             WRITELN('The user said yes.')
  353.         ELSE IF dismisser = 'no  ' THEN
  354.             WRITELN('The user said no.')
  355.         ELSE IF dismisser = 'cncl' THEN
  356.             WRITELN('The user cancelled the dialog.')
  357.         ELSE
  358.             WRITELN('I don''t know how the user responded');
  359.         {$ENDC}
  360.         aWindow.Close;
  361.         END;
  362.  
  363. {--------------------------------------------------------------------------------------------------}
  364.  
  365.     PROCEDURE MakeMarkDialog;
  366.  
  367.         VAR
  368.             aWindow:            TWindow;
  369.             dismisser:            IDType;
  370.             {$IFC qDebug}
  371.             theMark:            Str255;
  372.             {$ENDC}
  373.  
  374.         BEGIN
  375.         aWindow := NewTemplateWindow(aCmdNumber, NIL);
  376.         FailNIL(aWindow);
  377.         dismisser := TDialogView(aWindow.FindSubView('DLOG')).PoseModally;
  378.         {$IFC qDebug}
  379.         IF dismisser = 'ok  ' THEN
  380.             BEGIN
  381.             TEditText(aWindow.FindSubView('mark')).GetText(theMark);
  382.             IF (theMark = '') THEN
  383.                 WRITELN('No mark specified.')
  384.             ELSE
  385.                 WRITELN('The mark is ''', theMark, '''.');
  386.             END
  387.         ELSE
  388.             WRITELN('The dialog was cancelled.');
  389.         {$ENDC}
  390.         aWindow.Close;
  391.         END;
  392.  
  393. {--------------------------------------------------------------------------------------------------}
  394.  
  395.     PROCEDURE MakeDialog;
  396.  
  397.         VAR
  398.             aWindow:            TWindow;
  399.  
  400.         BEGIN
  401.         aWindow := NewTemplateWindow(aCmdNumber, NIL);
  402.         FailNIL(aWindow);
  403.         aWindow.Open;
  404.         END;
  405.  
  406. {--------------------------------------------------------------------------------------------------}
  407.  
  408.     PROCEDURE MakeFormatDialog;
  409.  
  410.         VAR
  411.             aWindow:            TWindow;
  412.             theDialog:            TDialogView;
  413.             dismisser:            IDType;
  414.  
  415. {--------------------------------------------------------------------------------------------------}
  416.         PROCEDURE SetupTheFontView;
  417.  
  418.             VAR
  419.                 theFontListView:    TFontListView;
  420.                 theSizeListView:    TSizeListView;
  421.  
  422.             BEGIN
  423.             theSizeListView := TSizeListView(theDialog.FindSubView('slst'));
  424.             theSizeListView.fSelection := 0;
  425.             theSizeListView.fSelectedSize := 9;
  426.             theFontListView := TFontListView(theDialog.FindSubView('flst'));
  427.             theFontListView.InitFontList;
  428.             theFontListView.SelectItem(1, kDontExtend, kHighlight, kSelect);
  429.             END;
  430.  
  431.         BEGIN
  432.         aWindow := NewTemplateWindow(aCmdNumber, NIL);
  433.         FailNIL(aWindow);
  434.         theDialog := TDialogView(aWindow.FindSubView('DLOG'));
  435.         SetupTheFontView;
  436.  
  437.         dismisser := theDialog.PoseModally;
  438.         {$IFC qDebug}
  439.         IF dismisser <> 'ok  ' THEN
  440.             WRITELN('The dialog was cancelled.');
  441.         {$ENDC}
  442.         aWindow.Close;
  443.         END;
  444.  
  445. {--------------------------------------------------------------------------------------------------}
  446.  
  447.     PROCEDURE MakePageSetupDialog;
  448.  
  449.         VAR
  450.             aWindow:            TWindow;
  451.             theDialog:            TPageSetupDialog;
  452.             dismisser:            IDType;
  453.             orientation:        VHSelect;
  454.  
  455.         BEGIN
  456.         aWindow := NewTemplateWindow(aCmdNumber, NIL);
  457.         FailNIL(aWindow);
  458.         theDialog := TPageSetupDialog(aWindow.FindSubView('DLOG'));
  459.         orientation := v;
  460.         theDialog.fOrientation := orientation;
  461.         TRadioIcon(theDialog.FindSubView('vert')).HiliteState(orientation = v, kDontRedraw);
  462.         TRadioIcon(theDialog.FindSubView('horz')).HiliteState(orientation = h, kDontRedraw);
  463.  
  464.         dismisser := theDialog.PoseModally;
  465.         {$IFC qDebug}
  466.         IF dismisser = 'ok  ' THEN
  467.             BEGIN
  468.             END
  469.         ELSE
  470.             WRITELN('The dialog was cancelled.');
  471.         {$ENDC}
  472.         aWindow.Close;
  473.         END;
  474.  
  475. {--------------------------------------------------------------------------------------------------}
  476.  
  477.     PROCEDURE MakeCalculator;
  478.  
  479.         VAR
  480.             aWindow:            TWindow;
  481.             aCalcDialog:        TCalcDialog;
  482.  
  483.         BEGIN
  484.         aWindow := NewTemplateWindow(aCmdNumber, NIL);
  485.         FailNIL(aWindow);
  486.         aCalcDialog := TCalcDialog(aWindow.FindSubView('DLOG'));
  487.         aCalcDialog.ClearSum;
  488.         aWindow.Open;
  489.         END;
  490.  
  491.     BEGIN
  492.     DoMenuCommand := NIL;
  493.     CASE aCmdNumber OF
  494.         cProcedureViews:
  495.             MakeProcedureViews;
  496.         cTemplateViews:
  497.             MakeTemplateViews;
  498.         cScrollingTest:
  499.             MakeScrollingTest;
  500.         cMonthlyDialog:
  501.             MakeMonthlyDialog;
  502.         cSaveDialog:
  503.             MakeSaveDialog;
  504.         cMarkDialog:
  505.             MakeMarkDialog;
  506.         cModelessMarkDialog:
  507.             MakeDialog;
  508.         cFormatDialog:
  509.             MakeFormatDialog;
  510.         cPageSetupDialog:
  511.             MakePageSetupDialog;
  512.         cHomeBrewControls:
  513.             MakeDialog;
  514.         cTabbingTest:
  515.             MakeDialog;
  516.         cCalculator:
  517.             MakeCalculator;
  518.         OTHERWISE
  519.             DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
  520.     END;
  521.     END;
  522.  
  523. {--------------------------------------------------------------------------------------------------}
  524. {$S ARes}
  525.  
  526. PROCEDURE TTestApplication.DoSetupMenus; OVERRIDE;
  527.  
  528.     VAR
  529.         i:                    INTEGER;
  530.  
  531.     BEGIN
  532.     INHERITED DoSetupMenus;
  533.  
  534.     FOR i := cFirstItem TO cLastItem DO
  535.         Enable(i, TRUE);
  536.     END;
  537.  
  538. {--------------------------------------------------------------------------------------------------}
  539. {$S AFields}
  540.  
  541. PROCEDURE TTestApplication.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  542.                                                  fieldType: INTEGER)); OVERRIDE;
  543.  
  544.     BEGIN
  545.     DoToField('TTestApplication', NIL, bClass);
  546.     INHERITED Fields(DoToField);
  547.     END;
  548.  
  549. {******************************************************************************************}
  550. {  T N u m b e r s V i e w                  }
  551. {******************************************************************************************}
  552. {--------------------------------------------------------------------------------------------------}
  553.  
  554. {$S ARes}
  555. PROCEDURE TNumbersView.Draw(area: Rect); OVERRIDE;
  556.  
  557.     VAR
  558.         viewRect:            VRect;
  559.         i, firstLine, lastLine: LONGINT;
  560.         vPt:                VPoint;
  561.         pt:                 Point;
  562.         s:                    Str255;
  563.  
  564.     BEGIN
  565.     QDToViewRect(area, viewRect);
  566.     viewRect.right := viewRect.right - 1;
  567.     viewRect.bottom := viewRect.bottom - 1;
  568.     firstLine := (viewRect.top DIV 16) + 1;
  569.     lastLine := (viewRect.bottom DIV 16) + 1;
  570.     SetPortTextStyle(gSystemStyle);
  571.     FOR i := firstLine TO lastLine DO
  572.         BEGIN
  573.         SetVPt(vPt, 0, i * 16);
  574.         pt := ViewToQDPt(vPt);
  575.         MoveTo(pt.h, pt.v);
  576.         NumToString(i, s);
  577.         DrawString(s);
  578.         END;
  579.  
  580.     INHERITED Draw(area);
  581.     END;
  582.  
  583. {--------------------------------------------------------------------------------------------------}
  584. {$S AFields}
  585.  
  586. PROCEDURE TNumbersView.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  587.                                                  fieldType: INTEGER)); OVERRIDE;
  588.  
  589.     BEGIN
  590.     DoToField('TNumbersView', NIL, bClass);
  591.     INHERITED Fields(DoToField);
  592.     END;
  593.  
  594. {******************************************************************************************}
  595. {  T M o n t h l y D i a l o g                 }
  596. {******************************************************************************************}
  597. {--------------------------------------------------------------------------------------------------}
  598. {$S AClose}
  599.  
  600. PROCEDURE TMonthlyDialog.DismissDialog(dismisser: IDType); OVERRIDE;
  601.  
  602.     VAR
  603.         i:                    INTEGER;
  604.  
  605.     BEGIN
  606.     FOR i := 1 TO 12 DO
  607.         gMonthlyValues[i] := TNumberText(FindSubView(gMonthIDs[i])).GetValue;
  608.     INHERITED DismissDialog(dismisser);
  609.     END;
  610.  
  611. {--------------------------------------------------------------------------------------------------}
  612. {$S ARes}
  613.  
  614. FUNCTION TMonthlyDialog.DoKeyCommand(ch: CHAR; aKeyCode: INTEGER;
  615.                                      VAR info: EventInfo): TCommand; OVERRIDE;
  616.  
  617.     BEGIN
  618.     { If option-tab is pressed, deselect the current edit text and leave nothing selected.
  619.       This is for test puropses only.  It is not part of the Macintosh user interface. }
  620.     IF (ch = chTab) & (info.theOptionKey) THEN
  621.         BEGIN
  622.         DoSelectEditText(NIL, FALSE);
  623.         DoKeyCommand := NIL;
  624.         END
  625.     ELSE
  626.         DoKeyCommand := INHERITED DoKeyCommand(ch, aKeyCode, info);
  627.     END;
  628.  
  629. {--------------------------------------------------------------------------------------------------}
  630.  
  631. {$S ARes}
  632. PROCEDURE TMonthlyDialog.StuffValues;
  633.  
  634.     VAR
  635.         i:                    INTEGER;
  636.  
  637.     BEGIN
  638.     FOR i := 1 TO 12 DO
  639.         TNumberText(FindSubView(gMonthIDs[i])).SetValue(gMonthlyValues[i], kDontRedraw);
  640.     END;
  641.  
  642. {--------------------------------------------------------------------------------------------------}
  643. {$S AFields}
  644.  
  645. PROCEDURE TMonthlyDialog.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  646.                                                  fieldType: INTEGER)); OVERRIDE;
  647.  
  648.     BEGIN
  649.     DoToField('TMonthlyDialog', NIL, bClass);
  650.     INHERITED Fields(DoToField);
  651.     END;
  652.  
  653. {**************************************************************************************************}
  654. {  T M o d e l e s s M a r k D i a l o g                                                           }
  655. {**************************************************************************************************}
  656. {--------------------------------------------------------------------------------------------------}
  657.  
  658. {$S ARes}
  659. PROCEDURE TModelessMarkDialog.DoChoice(origView: TView; itsChoice: INTEGER); OVERRIDE;
  660.  
  661.     {$IFC qDebug}
  662.     VAR
  663.         theMark:            Str255;
  664.         {$ENDC}
  665.  
  666.     BEGIN
  667.     CASE itsChoice OF
  668.         mDefaultKey,                                    { This handles when user presses the
  669.                                                          'return' key }
  670.         mCancelKey,                                     { This handles when user presses the 'esc'
  671.                                                          key }
  672.         mButtonHit:                                     { This handles clicking in 'OK' or 'Cancel'
  673.                                                          buttons }
  674.             IF origView.fIdentifier = fDefaultItem THEN
  675.                 BEGIN
  676.                 {$IFC qDebug}
  677.                 TEditText(FindSubView('mark')).GetText(theMark);
  678.                 WRITELN('The mark is ‘', theMark, '’');
  679.                 {$ENDC}
  680.                 GetWindow.Close;
  681.                 END
  682.             ELSE IF origView.fIdentifier = fCancelItem THEN
  683.                 GetWindow.Close;
  684.     END;
  685.     END;
  686.  
  687. {--------------------------------------------------------------------------------------------------}
  688. {$S AFields}
  689.  
  690. PROCEDURE TModelessMarkDialog.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  691.                                                  fieldType: INTEGER)); OVERRIDE;
  692.  
  693.     BEGIN
  694.     DoToField('TModelessMarkDialog', NIL, bClass);
  695.     INHERITED Fields(DoToField);
  696.     END;
  697.  
  698. {******************************************************************************************}
  699. {  T F o n t L i s t V i e w               }
  700. {******************************************************************************************}
  701.  
  702. {$S AOpen}
  703. PROCEDURE TFontListView.InitFontList;
  704.  
  705.     VAR
  706.         pFondIDs:            FontListPtr;
  707.         i:                    INTEGER;
  708.         noOfFonds:            INTEGER;
  709.         aString:            Str255;
  710.  
  711.     FUNCTION FondAfter(VAR fontName: Str255): INTEGER;
  712.     { Find the FOND whose name follows fontName alphabetically, and return its id and name }
  713.  
  714.         VAR
  715.             theFondResource:    Handle;
  716.             lastID:                INTEGER;
  717.             thisID:                INTEGER;
  718.             itsType:            ResType;
  719.             index:                INTEGER;
  720.             foundFOND:            BOOLEAN;
  721.             lastName:            Str255;
  722.             thisName:            Str255;
  723.  
  724.         BEGIN
  725.         lastID := 0;
  726.         foundFOND := FALSE;
  727.         lastName := '~~~~~~~~';
  728.         FOR index := 1 to noOfFonds DO
  729.             BEGIN
  730.             theFondResource := GetIndResource('FOND', index);
  731.             GetResInfo(theFondResource, thisID, itsType, thisName);
  732.             IF (thisName > fontName) & (thisName < lastName) THEN
  733.                 BEGIN
  734.                 lastID := thisID;
  735.                 CopyStr255(thisName, @lastName);
  736.                 foundFOND := TRUE;
  737.                 END;
  738.             END;
  739.         IF foundFOND THEN
  740.             CopyStr255(lastName, @fontName)
  741.         ELSE                                            { Skip duplicate FOND names }
  742.             fontName := '';
  743.         FondAfter := lastID;
  744.         END;
  745.  
  746.     BEGIN
  747.     fFontList := NIL;
  748.     noOfFonds := CountResources('FOND');
  749.     IF noOfFonds > kMaxFonds THEN
  750.         noOfFonds := kMaxFonds;
  751.     pFondIDs := FontListPtr(NewPermPtr(noOfFonds * sizeof(INTEGER)));
  752.     FailNIL(pFondIDs);
  753.  
  754.     aString := ' ';
  755.     FOR i := 1 TO noOfFonds DO
  756.         BEGIN                                            { put each FOND's id in the list… }
  757.         pFondIDs^[i] := FondAfter(aString);                { …in alphabetical order }
  758.         IF length(aString) = 0 THEN                        { we finished early }
  759.             BEGIN
  760.             noOfFonds := i-1;
  761.             LEAVE;
  762.             END;
  763.         END;
  764.  
  765.     fFontList := pFondIDs;
  766.     InsRowLast(noOfFonds, 16);
  767.     END;
  768.  
  769. {--------------------------------------------------------------------------------------------------}
  770.  
  771. {$S AClose}
  772. PROCEDURE TFontListView.Free; OVERRIDE;
  773.  
  774.     BEGIN
  775.     Ptr(fFontList) := DisposeIfPtr(fFontList);
  776.  
  777.     INHERITED Free;
  778.     END;
  779.  
  780. {--------------------------------------------------------------------------------------------------}
  781.  
  782. {$S ARes}
  783. PROCEDURE TFontListView.GetItemText(anItem: INTEGER; VAR aString: Str255); OVERRIDE;
  784.  
  785.     VAR
  786.         theFondResource:    Handle;
  787.         itsID:                INTEGER;
  788.         itsType:            ResType;
  789.  
  790.     BEGIN
  791.     theFondResource := GetResource('FOND', fFontList^[anItem]);
  792.     GetResInfo(theFondResource, itsID, itsType, aString);
  793.     END;
  794.  
  795. {--------------------------------------------------------------------------------------------------}
  796. {$S ARes}
  797.  
  798. PROCEDURE TFontListView.SelectItem(anItem: INTEGER; extendSelection, highlight,
  799.                                    select: BOOLEAN); OVERRIDE;
  800.  
  801.     VAR
  802.         aView:                TView;
  803.  
  804.     BEGIN
  805.     INHERITED SelectItem(anItem, extendSelection, highlight, select);
  806.  
  807.     IF select THEN
  808.         BEGIN
  809.         aView := GetWindow.FindSubView('slst');
  810.         FailNIL(aView);
  811.         TSizeListView(aView).InstallFontFamily(fFontList^[anItem]);
  812.         END;
  813.     END;
  814.  
  815. {--------------------------------------------------------------------------------------------------}
  816. {$S AFields}
  817.  
  818. PROCEDURE TFontListView.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  819.                                                  fieldType: INTEGER)); OVERRIDE;
  820.  
  821.     BEGIN
  822.     DoToField('TFontListView', NIL, bClass);
  823.     DoToField('fFontList', @fFontList, bPointer);
  824.     INHERITED Fields(DoToField);
  825.     END;
  826.  
  827. {******************************************************************************************}
  828. {  T S i z e L i s t V i e w               }
  829. {******************************************************************************************}
  830.  
  831. {--------------------------------------------------------------------------------------------------}
  832.  
  833. {$S ARes}
  834. PROCEDURE TSizeListView.GetItemText(anItem: INTEGER; VAR aString: Str255); OVERRIDE;
  835.  
  836.     VAR
  837.         noOfSizes:            INTEGER;
  838.         theFond:            FondHandle;
  839.         i:                    INTEGER;
  840.  
  841.     BEGIN
  842.     theFond := FondHandle(GetResource('FOND', fFondID));
  843.     noOfSizes := 0;
  844.     FOR i := 0 TO theFond^^.noOfFonts DO
  845.         BEGIN
  846.         IF theFond^^.fontStuff[i].style = 0 THEN
  847.             noOfSizes := noOfSizes + 1;
  848.         IF noOfSizes = anItem THEN
  849.             BEGIN
  850.             NumToString(theFond^^.fontStuff[i].size, aString);
  851.             EXIT(GetItemText);
  852.             END;
  853.         END;
  854.     aString := '';
  855.     END;
  856.  
  857. {--------------------------------------------------------------------------------------------------}
  858.  
  859. {$S AOpen}
  860. PROCEDURE TSizeListView.InstallFontFamily(theFondID: INTEGER);
  861.  
  862.     VAR
  863.         theFond:            FondHandle;
  864.         noOfSizes:            INTEGER;
  865.         i:                    INTEGER;
  866.         sizeToSelect:        INTEGER;
  867.  
  868.     BEGIN
  869.     theFond := FondHandle(GetResource('FOND', theFondID));
  870.     noOfSizes := 0;
  871.     sizeToSelect := 0;
  872.     FOR i := 0 TO theFond^^.noOfFonts DO
  873.         IF theFond^^.fontStuff[i].style = 0 THEN
  874.             BEGIN
  875.             noOfSizes := noOfSizes + 1;
  876.             IF theFond^^.fontStuff[i].size = fSelectedSize THEN
  877.                 sizeToSelect := noOfSizes;
  878.             END;
  879.     fFondID := theFondID;
  880.     SetNumberOfItems(noOfSizes);
  881.     SelectItem(sizeToSelect, kDontExtend, kDontHighlight, kSelect);
  882.     ForceRedraw;
  883.     END;
  884.  
  885. {--------------------------------------------------------------------------------------------------}
  886.  
  887. {$S ARes}
  888. PROCEDURE TSizeListView.SelectItem(anItem: INTEGER; extendSelection, highlight,
  889.                                    select: BOOLEAN); OVERRIDE;
  890.  
  891.     VAR
  892.         aString:            Str255;
  893.         theSizeView:        TNumberText;
  894.         fontSize:            LONGINT;
  895.  
  896.     BEGIN
  897.     INHERITED SelectItem(anItem, extendSelection, highlight, select);
  898.  
  899.     IF select AND (anItem <> 0) THEN
  900.         BEGIN
  901.         GetItemText(anItem, aString);
  902.         theSizeView := TNumberText(GetWindow.FindSubView('size'));
  903.         theSizeView.SetText(aString, kRedraw);
  904.         theSizeView.SetSelection(0, MAXINT, kRedraw);
  905.         StringToNum(aString, fontSize);
  906.         fSelectedSize := fontSize;
  907.         END;
  908.     END;
  909.  
  910. {--------------------------------------------------------------------------------------------------}
  911. {$S ARes}
  912.  
  913. PROCEDURE TSizeListView.SetNumberOfItems(aNumber: INTEGER);
  914.  
  915.     BEGIN
  916.     SelectItem(0, kDontExtend, kHighlight, kSelect);
  917.  
  918.     IF fNumOfRows > aNumber THEN
  919.         BEGIN
  920.         DelItemFirst(fNumOfRows - aNumber);
  921.         END
  922.     ELSE IF fNumOfRows < aNumber THEN
  923.         BEGIN
  924.         InsItemFirst(aNumber - fNumOfRows);
  925.         END;
  926.     END;
  927.  
  928. {--------------------------------------------------------------------------------------------------}
  929. {$S AFields}
  930.  
  931. PROCEDURE TSizeListView.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  932.                                                  fieldType: INTEGER)); OVERRIDE;
  933.  
  934.     BEGIN
  935.     DoToField('TSizeListView', NIL, bClass);
  936.     DoToField('fSelection', @fSelection, bInteger);
  937.     DoToField('fSelectedSize', @fSelectedSize, bInteger);
  938.     DoToField('fFondID', @fFondID, bInteger);
  939.     INHERITED Fields(DoToField);
  940.     END;
  941.  
  942. {******************************************************************************************}
  943. {  T P a g e S e t u p D i a l o g                }
  944. {******************************************************************************************}
  945. {--------------------------------------------------------------------------------------------------}
  946.  
  947. {$S ARes}
  948. PROCEDURE TPageSetupDialog.DoChoice(origView: TView; itsChoice: INTEGER); OVERRIDE;
  949.  
  950.     VAR
  951.         newOrientation:     VHSelect;
  952.         tallAdjCheckBox:    TCheckBox;
  953.  
  954.     BEGIN
  955.     CASE itsChoice OF
  956.         mIconHit:
  957.             BEGIN
  958.             IF origView.fIdentifier = 'vert' THEN
  959.                 newOrientation := v
  960.             ELSE
  961.                 newOrientation := h;
  962.             IF newOrientation <> fOrientation THEN
  963.                 BEGIN
  964.                 TRadioIcon(FindSubView('vert')).HiliteState(newOrientation = v, kRedraw);
  965.                 TRadioIcon(FindSubView('horz')).HiliteState(newOrientation = h, kRedraw);
  966.                 tallAdjCheckBox := TCheckBox(FindSubView('tall'));
  967.                 tallAdjCheckBox.DimState(newOrientation = h, kRedraw);
  968.                 tallAdjCheckBox.SetState(FALSE, kRedraw);
  969.                 fOrientation := newOrientation;
  970.                 END;
  971.             END;
  972.         OTHERWISE
  973.             INHERITED DoChoice(origView, itsChoice);
  974.     END;
  975.     END;
  976.  
  977. {--------------------------------------------------------------------------------------------------}
  978. {$S AFields}
  979.  
  980. PROCEDURE TPageSetupDialog.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  981.                                                  fieldType: INTEGER)); OVERRIDE;
  982.  
  983.     BEGIN
  984.     DoToField('TPageSetupDialog', NIL, bClass);
  985.     DoToField('fOrientation', @fOrientation, bVHSelect);
  986.     INHERITED Fields(DoToField);
  987.     END;
  988.  
  989. {******************************************************************************************}
  990. {  T R a d i o I c o n                   }
  991. {******************************************************************************************}
  992. {--------------------------------------------------------------------------------------------------}
  993. {$S ADoCommand}
  994.  
  995. PROCEDURE TRadioIcon.TrackMouse(aTrackPhase: TrackPhase; VAR anchorPoint, previousPoint,
  996.                                 nextPoint: VPoint; mouseDidMove: BOOLEAN); OVERRIDE;
  997.  
  998.     BEGIN
  999.     IF aTrackPhase = TrackPress THEN
  1000.         DoChoice(SELF, mIconHit);
  1001.     END;
  1002.  
  1003. {--------------------------------------------------------------------------------------------------}
  1004. {$S AFields}
  1005.  
  1006. PROCEDURE TRadioIcon.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  1007.                                                  fieldType: INTEGER)); OVERRIDE;
  1008.  
  1009.     BEGIN
  1010.     DoToField('TRadioIcon', NIL, bClass);
  1011.     INHERITED Fields(DoToField);
  1012.     END;
  1013.  
  1014. {******************************************************************************************}
  1015. {  T H o m e B r e w D i a l o g              }
  1016. {******************************************************************************************}
  1017. {--------------------------------------------------------------------------------------------------}
  1018. {$S ARes}
  1019. FUNCTION THomeBrewDialog.DoSetCursor(localPoint: Point; cursorRgn: RgnHandle): BOOLEAN; OVERRIDE;
  1020.  
  1021.     VAR
  1022.         theCursor:            CursHandle;
  1023.         qdExtent:            Rect;
  1024.  
  1025.     BEGIN
  1026.     theCursor := GetCursor(crossCursor);
  1027.     SetCursor(theCursor^^);
  1028.     GetQDExtent(qdExtent);
  1029.     RectRgn(cursorRgn, qdExtent);
  1030.     DoSetCursor := TRUE;
  1031.     END;
  1032.  
  1033. {--------------------------------------------------------------------------------------------------}
  1034. {$S ARes}
  1035. FUNCTION THomeBrewDialog.HandleCursor(theMouse: VPoint; cursorRgn: RgnHandle): TView; OVERRIDE;
  1036.  
  1037.     BEGIN
  1038.     IF Focus & DoSetCursor(ViewToQDPt(theMouse), cursorRgn) THEN
  1039.         HandleCursor := SELF
  1040.     ELSE
  1041.         HandleCursor := NIL;
  1042.     END;
  1043.  
  1044. {--------------------------------------------------------------------------------------------------}
  1045. {$S AFields}
  1046.  
  1047. PROCEDURE THomeBrewDialog.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  1048.                                                  fieldType: INTEGER)); OVERRIDE;
  1049.  
  1050.     BEGIN
  1051.     DoToField('THomeBrewDialog', NIL, bClass);
  1052.     INHERITED Fields(DoToField);
  1053.     END;
  1054.  
  1055. {******************************************************************************************}
  1056. {  T A r r o w s C o n t r o l                 }
  1057. {******************************************************************************************}
  1058. {--------------------------------------------------------------------------------------------------}
  1059.  
  1060. {$S AOpen}
  1061. PROCEDURE TArrowsControl.IRes(itsDocument: TDocument; itsSuperView: TView;
  1062.     VAR itsParams: Ptr); OVERRIDE;
  1063.  
  1064.     BEGIN
  1065.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  1066.     fLastChange := 0;
  1067.     END;
  1068.  
  1069. {--------------------------------------------------------------------------------------------------}
  1070.  
  1071. {$S ARes}
  1072. PROCEDURE TArrowsControl.TrackMouse(aTrackPhase: TrackPhase; VAR anchorPoint, previousPoint,
  1073.                                     nextPoint: VPoint; mouseDidMove: BOOLEAN); OVERRIDE;
  1074.  
  1075.     BEGIN
  1076.     IF TickCount >= fLastChange + 5 THEN
  1077.         BEGIN
  1078.         fLastChange := TickCount;
  1079.         IF aTrackPhase = TrackPress THEN
  1080.             fLastChange := fLastChange + 10;
  1081.  
  1082.         IF ContainsMouse(nextPoint) THEN
  1083.             IF nextPoint.v <= fSize.v DIV 2 THEN
  1084.                 DoChoice(SELF, mUpArrow)
  1085.             ELSE
  1086.                 DoChoice(SELF, mDownArrow);
  1087.         END;
  1088.     END;
  1089.  
  1090. {--------------------------------------------------------------------------------------------------}
  1091. {$S AFields}
  1092.  
  1093. PROCEDURE TArrowsControl.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  1094.                                                  fieldType: INTEGER)); OVERRIDE;
  1095.  
  1096.     BEGIN
  1097.     DoToField('TArrowsControl', NIL, bClass);
  1098.     DoToField('fLastChange', @fLastChange, bLongint);
  1099.     INHERITED Fields(DoToField);
  1100.     END;
  1101.  
  1102. {******************************************************************************************}
  1103. {  TTemperatureCluster                  }
  1104. {******************************************************************************************}
  1105. {--------------------------------------------------------------------------------------------------}
  1106. {$S ARes}
  1107.  
  1108. PROCEDURE TTemperatureCluster.DoChoice(origView : TView;itsChoice : INTEGER); OVERRIDE;
  1109. VAR
  1110.     theNumberText:        TNumberText;
  1111.     theNumber:            LONGINT;
  1112.  
  1113. BEGIN
  1114.     CASE itsChoice OF
  1115.         mUpArrow, mDownArrow:
  1116.             BEGIN
  1117.             theNumberText := TNumberText(FindSubView('Numb'));
  1118.             theNumber := theNumberText.GetValue;
  1119.             IF itsChoice = mUpArrow THEN
  1120.                 theNumber := theNumber + 1
  1121.             ELSE
  1122.                 theNumber := theNumber - 1;
  1123.             theNumberText.SetValue(theNumber, kRedraw);
  1124.             INHERITED DoChoice(SELF,mTemperatureChanged);
  1125.             END;
  1126.         OTHERWISE
  1127.             INHERITED DoChoice(origView, itsChoice);
  1128.     END;
  1129. END;
  1130.  
  1131. {--------------------------------------------------------------------------------------------------}
  1132. {$S ARes}
  1133.  
  1134. FUNCTION  TTemperatureCluster.GetValue: LONGINT;
  1135. VAR numberText : TNumberText;
  1136. BEGIN
  1137.     numberText := TNumberText(SELF.FindSubView('Numb'));
  1138.     GetValue := numberText.GetValue;
  1139. END;
  1140.  
  1141. {--------------------------------------------------------------------------------------------------}
  1142. {$S ARes}
  1143.  
  1144. PROCEDURE TTemperatureCluster.SetValue(newValue: LONGINT;
  1145.                                redraw: BOOLEAN);
  1146. VAR numberText : TNumberText;
  1147. BEGIN
  1148.     numberText := TNumberText(SELF.FindSubView('Numb'));
  1149.     numberText.SetValue(newValue,redraw);
  1150. END;
  1151.  
  1152. {--------------------------------------------------------------------------------------------------}
  1153. {$S AFields}
  1154.  
  1155. PROCEDURE TTemperatureCluster.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  1156.                                                  fieldType: INTEGER)); OVERRIDE;
  1157.  
  1158.     BEGIN
  1159.     DoToField('TTemperatureCluster', NIL, bClass);
  1160.     INHERITED Fields(DoToField);
  1161.     END;
  1162.  
  1163. {******************************************************************************************}
  1164. {  TTemperatureConversionCluster    }
  1165. {******************************************************************************************}
  1166. {--------------------------------------------------------------------------------------------------}
  1167. {$S ARes}
  1168.  
  1169. PROCEDURE TTemperatureConversionCluster.DoChoice(origView: TView; itsChoice: INTEGER); OVERRIDE;
  1170.  
  1171.     VAR
  1172.         Celsius, Fahrenheit: TTemperatureCluster;
  1173.  
  1174.     BEGIN
  1175.     IF itsChoice = mTemperatureChanged THEN
  1176.         BEGIN
  1177.         Celsius := TTemperatureCluster(FindSubView('Cels'));
  1178.         Fahrenheit := TTemperatureCluster(FindSubView('Fahr'));
  1179.         IF origView = Celsius THEN
  1180.             Fahrenheit.SetValue(TRUNC(Celsius.GetValue * 1.8 + 32), kRedraw)
  1181.         ELSE IF origView = Fahrenheit THEN
  1182.             Celsius.SetValue(TRUNC((Fahrenheit.GetValue - 32) / 1.8), kRedraw)
  1183.         END
  1184.     ELSE
  1185.         INHERITED DoChoice(origView, itsChoice);
  1186.     END;
  1187.  
  1188. {--------------------------------------------------------------------------------------------------}
  1189. {$S AFields}
  1190.  
  1191. PROCEDURE TTemperatureConversionCluster.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  1192.                                                  fieldType: INTEGER)); OVERRIDE;
  1193.  
  1194.     BEGIN
  1195.     DoToField('TTemperatureConversionCluster', NIL, bClass);
  1196.     INHERITED Fields(DoToField);
  1197.     END;
  1198.  
  1199. {******************************************************************************************}
  1200. {  T S l i d e r                  }
  1201. {******************************************************************************************}
  1202. {--------------------------------------------------------------------------------------------------}
  1203.  
  1204. {$S AOpen}
  1205. PROCEDURE TSlider.IRes(itsDocument: TDocument; itsSuperView: TView; VAR itsParams: Ptr); OVERRIDE;
  1206.  
  1207.     VAR
  1208.         knobPicture:        PicHandle;
  1209.         knobRect:            Rect;
  1210.  
  1211.     BEGIN
  1212.     INHERITED IRes(NIL, itsSuperView, itsParams);
  1213.     knobPicture := GetPicture(1002);
  1214.     fKnobPicture := knobPicture;
  1215.     WITH knobPicture^^.picFrame DO
  1216.         BEGIN
  1217.         SetPt(knobRect.topLeft, fSize.h - (right - left), fSize.v - 16);
  1218.         knobRect.right := knobRect.left + right - left;
  1219.         knobRect.bottom := knobRect.top + bottom - top;
  1220.         END;
  1221.     fMaxTop := knobRect.top;
  1222.     fMinTop := knobRect.top - 84;
  1223.     fKnobRect := knobRect;
  1224.     fValue := 0;
  1225.     END;
  1226.  
  1227. {--------------------------------------------------------------------------------------------------}
  1228.  
  1229. {$S ARes}
  1230. FUNCTION TSlider.ContainsMouse(theMouse: VPoint): BOOLEAN; OVERRIDE;
  1231.  
  1232.     VAR
  1233.         knobRect:            Rect;
  1234.  
  1235.     BEGIN
  1236.     GetKnobRect(knobRect);
  1237.     ContainsMouse := PtInRect(VPtToPt(theMouse), knobRect);
  1238.     END;
  1239.  
  1240. {--------------------------------------------------------------------------------------------------}
  1241.  
  1242. {$S ARes}
  1243. PROCEDURE TSlider.Draw(area: Rect); OVERRIDE;
  1244.  
  1245.     BEGIN
  1246.     INHERITED Draw(area);                                { This draws everything but the knob }
  1247.     DrawKnob;
  1248.     END;
  1249.  
  1250. {--------------------------------------------------------------------------------------------------}
  1251.  
  1252. {$S ARes}
  1253. PROCEDURE TSlider.DrawKnob;
  1254.  
  1255.     VAR
  1256.         knobRect:            Rect;
  1257.  
  1258.     BEGIN
  1259.     GetKnobRect(knobRect);
  1260.     LoadResource(Handle(fKnobPicture));                 { In case it was purged from memory }
  1261.     DrawPicture(fKnobPicture, knobRect);
  1262.     END;
  1263.  
  1264. {--------------------------------------------------------------------------------------------------}
  1265.  
  1266. {$S ARes}
  1267. PROCEDURE TSlider.GetKnobRect(VAR knobRect: Rect);
  1268.  
  1269.     BEGIN
  1270.     knobRect := fKnobRect;
  1271.     OffsetRect(knobRect, 0, - (fValue * 12));
  1272.     END;
  1273.  
  1274. {--------------------------------------------------------------------------------------------------}
  1275.  
  1276. {$S ARes}
  1277. PROCEDURE TSlider.TrackMouse(aTrackPhase: TrackPhase; VAR anchorPoint, previousPoint,
  1278.                              nextPoint: VPoint; mouseDidMove: BOOLEAN); OVERRIDE;
  1279.  
  1280.     VAR
  1281.         oldRect:            Rect;
  1282.         newRect:            Rect;
  1283.         difference:         Rect;
  1284.         savedClip:            RgnHandle;
  1285.         base:                INTEGER;
  1286.         offset:             INTEGER;
  1287.  
  1288.     BEGIN
  1289.     GetKnobRect(oldRect);
  1290.     newRect := oldRect;
  1291.  
  1292.     { Compute rectangle of knob's current position }
  1293.     offset := Min(Max(previousPoint.v - anchorPoint.v, fMinTop - newRect.top), fMaxTop -
  1294.                   newRect.top);
  1295.     OffsetRect(oldRect, 0, offset);
  1296.  
  1297.     { Compute rectangle of knob's new position }
  1298.     offset := Min(Max(nextPoint.v - anchorPoint.v, fMinTop - newRect.top), fMaxTop - newRect.top);
  1299.     OffsetRect(newRect, 0, offset);
  1300.  
  1301.     { If the mouse was release, pin the knob to a value and set slider's value }
  1302.     IF aTrackPhase = TrackRelease THEN
  1303.         BEGIN
  1304.         base := fSize.v - 16 - newRect.top;
  1305.         offset := base - ((base + 6) DIV 12 * 12);
  1306.         OffsetRect(newRect, 0, offset);
  1307.         fValue := (fSize.v - 16 - newRect.top) DIV 12;
  1308.         END;
  1309.  
  1310.     { To redraw minimal amount, compute difference between old and new positions }
  1311.     difference := oldRect;
  1312.     IF oldRect.top > newRect.top THEN
  1313.         difference.top := Max(oldRect.top, newRect.bottom)
  1314.     ELSE
  1315.         difference.bottom := Min(oldRect.bottom, newRect.top);
  1316.  
  1317.     savedClip := NewRgn;
  1318.     FailNIL(savedClip);
  1319.     GetClip(savedClip);
  1320.  
  1321.     ClipRect(difference);
  1322.     INHERITED Draw(difference);
  1323.  
  1324.     SetClip(savedClip);
  1325.     DisposeRgn(savedClip);
  1326.  
  1327.     LoadResource(Handle(fKnobPicture));                 { In case it was purged from memory }
  1328.     DrawPicture(fKnobPicture, newRect);
  1329.     END;
  1330.  
  1331. {--------------------------------------------------------------------------------------------------}
  1332. {$S AFields}
  1333.  
  1334. PROCEDURE TSlider.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  1335.                                                  fieldType: INTEGER)); OVERRIDE;
  1336.  
  1337.     BEGIN
  1338.     DoToField('TSlider', NIL, bClass);
  1339.     DoToField('fValue', @fValue, bInteger);
  1340.     DoToField('fKnobPicture', @fKnobPicture, bHandle);
  1341.     DoToField('fKnobRect', @fKnobRect, bRect);
  1342.     DoToField('fMinTop', @fMinTop, bInteger);
  1343.     DoToField('fMaxTop', @fMaxTop, bInteger);
  1344.     INHERITED Fields(DoToField);
  1345.     END;
  1346.  
  1347. {******************************************************************************************}
  1348. {  T S u m S t a t i c T e x t                 }
  1349. {******************************************************************************************}
  1350.  
  1351. {$S ARes}
  1352. PROCEDURE TSumStaticText.Draw(area: Rect); OVERRIDE;
  1353.  
  1354.     VAR
  1355.         theRect:            Rect;
  1356.  
  1357.     BEGIN
  1358.     { Make sure the gray background gets completely erased }
  1359.     GetQDExtent(theRect);
  1360.     InsetRect(theRect, fPenSize.h, fPenSize.v);
  1361.     EraseRect(theRect);
  1362.     INHERITED Draw(area);
  1363.     END;
  1364.  
  1365. {--------------------------------------------------------------------------------------------------}
  1366. {$S AFields}
  1367.  
  1368. PROCEDURE TSumStaticText.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  1369.                                                  fieldType: INTEGER)); OVERRIDE;
  1370.  
  1371.     BEGIN
  1372.     DoToField('TSumStaticText', NIL, bClass);
  1373.     INHERITED Fields(DoToField);
  1374.     END;
  1375.  
  1376. {******************************************************************************************}
  1377. {  T C a l c D i a l o g                }
  1378. {******************************************************************************************}
  1379. {--------------------------------------------------------------------------------------------------}
  1380.  
  1381. {$S ARes}
  1382. PROCEDURE TCalcDialog.DoChoice(origView: TView; itsChoice: INTEGER); OVERRIDE;
  1383.  
  1384.     VAR
  1385.         origID:             IDType;
  1386.  
  1387.     BEGIN
  1388.     origID := origView.fIdentifier;
  1389.     CASE itsChoice OF
  1390.         mOKHit:
  1391.             CASE origID[4] OF
  1392.                 'C':
  1393.                     ClearSum;
  1394.                 '=', 'E':
  1395.                     TotalSum(noOperator);
  1396.                 '/':
  1397.                     TotalSum(divOperator);
  1398.                 '*':
  1399.                     TotalSum(mulOperator);
  1400.                 '-':
  1401.                     TotalSum(subOperator);
  1402.                 '+':
  1403.                     TotalSum(addOperator);
  1404.                 OTHERWISE
  1405.                     NewDigit(origID[4]);
  1406.             END;
  1407.         OTHERWISE
  1408.             INHERITED DoChoice(origView, itsChoice);
  1409.     END;
  1410.     END;
  1411.  
  1412. {--------------------------------------------------------------------------------------------------}
  1413.  
  1414. {$S ARes}
  1415. FUNCTION TCalcDialog.DoKeyCommand(ch: CHAR; aKeyCode: INTEGER;
  1416.                                   VAR info: EventInfo): TCommand; OVERRIDE;
  1417.  
  1418.     VAR
  1419.         foundIt:            BOOLEAN;
  1420.         whoCares:            LONGINT;
  1421.         theID:                IDType;
  1422.         theView:            TView;
  1423.  
  1424.     BEGIN
  1425.     foundIt := TRUE;
  1426.     IF aKeyCode = $47 THEN                                { Clear key }
  1427.         theID := 'keyC'
  1428.     ELSE IF (ch = chEnter) | (ch = chReturn) THEN
  1429.         theID := 'keyE'
  1430.     ELSE
  1431.         CASE ch OF
  1432.             '0'..'9', '.', '+', '-', '*', '/', '=':
  1433.                 BEGIN
  1434.                 theID := 'key ';
  1435.                 theID[4] := ch;
  1436.                 END;
  1437.             OTHERWISE
  1438.                 BEGIN
  1439.                 foundIt := FALSE;
  1440.                 SysBeep(1);
  1441.                 END;
  1442.         END;
  1443.     IF foundIt THEN
  1444.         BEGIN
  1445.         theView := FindSubView(theID);
  1446.         IF theView.Focus THEN
  1447.             BEGIN
  1448.             TControl(theView).Hilite;
  1449.             Delay(5, whoCares);
  1450.             TControl(theView).Hilite;
  1451.             END;
  1452.         DoChoice(theView, mOKHit);
  1453.         END;
  1454.     DoKeyCommand := NIL;
  1455.     END;
  1456.  
  1457. {--------------------------------------------------------------------------------------------------}
  1458.  
  1459. {$S ARes}
  1460. PROCEDURE TCalcDialog.ClearSum;
  1461.  
  1462.     BEGIN
  1463.     fArgument := 0;
  1464.     fSum := 0;
  1465.     fOperator := noOperator;
  1466.     fDecimalPoint := FALSE;
  1467.     fRestart := TRUE;
  1468.     TStaticText(FindSubView('SUMM')).SetText('0', TRUE);
  1469.     END;
  1470.  
  1471. {--------------------------------------------------------------------------------------------------}
  1472.  
  1473. {$S ARes}
  1474. PROCEDURE TCalcDialog.FetchValue(VAR aValue: Extended);
  1475.  
  1476.     VAR
  1477.         theStr:             Str255;
  1478.  
  1479.     BEGIN
  1480.     TStaticText(FindSubView('SUMM')).GetText(theStr);
  1481.     aValue := Str2Num(theStr);
  1482.     END;
  1483.  
  1484. {--------------------------------------------------------------------------------------------------}
  1485.  
  1486. {$S ARes}
  1487. PROCEDURE TCalcDialog.SetValue;
  1488.  
  1489.     VAR
  1490.         thePos:             INTEGER;
  1491.         theStr:             Str255;
  1492.         theForm:            DecForm;
  1493.         anExtended:         Extended;
  1494.  
  1495. {--------------------------------------------------------------------------------------------------}
  1496.     PROCEDURE Truncate;
  1497.  
  1498.         VAR
  1499.             theChar:            CHAR;
  1500.  
  1501.         BEGIN
  1502.         IF LENGTH(theStr) > 1 THEN
  1503.             BEGIN
  1504.             theChar := theStr[LENGTH(theStr)];
  1505.             IF (theChar = '0') | (theChar = '.') THEN
  1506.                 Delete(theStr, LENGTH(theStr), 1);
  1507.             IF theChar = '0' THEN
  1508.                 Truncate;
  1509.             END;
  1510.         END;
  1511.  
  1512.     BEGIN
  1513.     theForm.style := FixedDecimal;
  1514.     theForm.Digits := 2 * kMaxPlaces;
  1515.     anExtended := fSum;
  1516.     Num2Str(theForm, anExtended, DecStr(theStr));
  1517.     thePos := POS('.', theStr);
  1518.     IF thePos <> 0 THEN
  1519.         Truncate;
  1520.     IF (thePos > kMaxPlaces) | ((thePos <> 0) & (POS('000000', theStr) = thePos + 1)) THEN
  1521.         BEGIN
  1522.         theForm.style := FloatDecimal;
  1523.         theForm.Digits := 2;
  1524.         anExtended := fSum;
  1525.         Num2Str(theForm, anExtended, DecStr(theStr));
  1526.         END;
  1527.     IF LENGTH(theStr) > kMaxPlaces THEN
  1528.         theStr[0] := CHR(kMaxPlaces);
  1529.     TStaticText(FindSubView('SUMM')).SetText(theStr, TRUE);
  1530.     END;
  1531.  
  1532. {--------------------------------------------------------------------------------------------------}
  1533.  
  1534. {$S ARes}
  1535. PROCEDURE TCalcDialog.TotalSum(newOperator: CalcOperator);
  1536.  
  1537.     VAR
  1538.         aValue: Extended;
  1539.     BEGIN
  1540.     FetchValue(aValue);
  1541.     fArgument := aValue;
  1542.     CASE fOperator OF
  1543.         noOperator:
  1544.             fSum := fArgument;
  1545.         divOperator:
  1546.             fSum := fSum / fArgument;
  1547.         mulOperator:
  1548.             fSum := fSum * fArgument;
  1549.         subOperator:
  1550.             fSum := fSum - fArgument;
  1551.         addOperator:
  1552.             fSum := fSum + fArgument;
  1553.     END;
  1554.     SetValue;
  1555.     fRestart := TRUE;
  1556.     fArgument := fSum;
  1557.     fOperator := newOperator;
  1558.     END;
  1559.  
  1560. {--------------------------------------------------------------------------------------------------}
  1561.  
  1562. {$S ARes}
  1563. PROCEDURE TCalcDialog.NewDigit(theNumber: CHAR);
  1564.  
  1565.     VAR
  1566.         theText:            TStaticText;
  1567.         theStr:             Str255;
  1568.  
  1569. {--------------------------------------------------------------------------------------------------}
  1570.  
  1571.     PROCEDURE SetIt;
  1572.  
  1573.         BEGIN
  1574.         theStr[LENGTH(theStr) + 1] := theNumber;
  1575.         theStr[0] := CHR(LENGTH(theStr) + 1);
  1576.         theText.SetText(theStr, TRUE);
  1577.         END;
  1578.  
  1579.     BEGIN
  1580.     theText := TStaticText(FindSubView('SUMM'));
  1581.     IF fRestart THEN
  1582.         theStr := ''
  1583.     ELSE
  1584.         theText.GetText(theStr);
  1585.  
  1586.     IF LENGTH(theStr) < kMaxPlaces THEN
  1587.         BEGIN
  1588.         fRestart := FALSE;
  1589.         IF (theNumber = '.') AND NOT fDecimalPoint THEN
  1590.             fDecimalPoint := TRUE;
  1591.         SetIt;
  1592.         END;
  1593.     END;
  1594.  
  1595. {--------------------------------------------------------------------------------------------------}
  1596.  
  1597. {$S AFields}
  1598.  
  1599. PROCEDURE TCalcDialog.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  1600.                                                  fieldType: INTEGER)); OVERRIDE;
  1601.  
  1602.     BEGIN
  1603.     DoToField('TCalcDialog', NIL, bClass);
  1604.     DoToField('fSum', @fSum, bExtended);
  1605.     DoToField('fArgument', @fArgument, bExtended);
  1606.     DoToField('fOperator', @fOperator, bInteger);
  1607.     DoToField('fDecimalPoint', @fDecimalPoint, bBoolean);
  1608.     DoToField('fRestart', @fRestart, bBoolean);
  1609.     INHERITED Fields(DoToField);
  1610.     END;
  1611.